﻿#include "CMainWidget.h"

#include <QButtonGroup>

#include "version.h"

CMainWidget::CMainWidget(QWidget *parent) :
    QWidget(parent)
{
    ui.setupUi(this);
    setWindowTitle(tr("Quality Inspection Tool %1").arg(QIT_VERSION));

    // init navi buttons
    QButtonGroup *btns = new QButtonGroup(this);
    btns->addButton(ui.btn_navi1, 0);
    btns->addButton(ui.btn_navi2, 1);
    btns->addButton(ui.btn_navi3, 2);
    connect(btns, SIGNAL(buttonClicked(int)), this, SLOT(event_navi_changed(int)));

    ui.wnd_header->hide();
    ui.wnd_content->setCurrentIndex(1);
}

CMainWidget::~CMainWidget()
{
}

void CMainWidget::SetUp()
{
    ui.page_device_control->SetUp();
}

void CMainWidget::showEvent(QShowEvent *e)
{
    return QWidget::showEvent(e);
}

void CMainWidget::on_btn_back_to_home_clicked()
{
    ui.wnd_content->setCurrentIndex(0);
    setWindowTitle(tr("Quality Inspection Tool %1").arg(QIT_VERSION));
}

void CMainWidget::event_navi_changed(int index)
{
    ui.wnd_content->setCurrentIndex(index + 1);

    auto sub_title = ui.wnd_content->currentWidget()->windowTitle();
    if (sub_title.isEmpty())
    {
        setWindowTitle(tr("Quality Inspection Tool %1").arg(QIT_VERSION));
        return;
    }
    setWindowTitle(QString("%1 - %2").arg(sub_title).arg(tr("Quality Inspection Tool %1").arg(QIT_VERSION)));
}
